<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教师信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>教师姓名：</label>
                                <input type="text" name="teacherName"/>
                            </li>
                            <li>
                                <label>教师工号：</label>
                                <input type="text" name="teacherNo"/>
                            </li>
                            <li>
                                <label>专业名称：</label>
<!--                                <input type="text" name="majorName"/>-->
                                <select name="majorId" class="form-control">
                                    <option value="">全部</option>
                                    <option th:each="major:${majors}" th:value="${major.majorId}" th:text="${major.majorName}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否在职：</label>
                                <select name="isActive" th:with="type=${@dict.getType('sys_position_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="college:teacher:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="college:teacher:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="college:teacher:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="college:teacher:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-warning" onclick="$.table.exportTemplate()" shiro:hasPermission="college:teacher:exportTemplate">
                    <i class="fa fa-download"></i> 下载模板
                </a>
                <a class="btn btn-success" onclick="$.table.importExcel()" shiro:hasPermission="college:teacher:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var isActiveDatas = [[${@dict.getType('sys_position_status')}]];
        var editFlag = [[${@permission.hasPermi('college:teacher:edit')}]];
        var removeFlag = [[${@permission.hasPermi('college:teacher:remove')}]];
        var prefix = ctx + "college/teacher";
        var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                exportTemplateUrl: prefix + "/exportTemplate",
                importUrl: prefix + "/import",
                modalName: "教师信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'teacherId',
                    title: '教师ID',
                    visible: false
                },
                {
                    field: 'teacherName',
                    title: '教师姓名'
                },
                {
                    field: 'teacherNo',
                    title: '教师工号'
                },
                {
                    field: 'majorName',
                    title: '专业名称'
                },
                {
                    field: 'title',
                    title: '职称'
                },
                {
                    field: 'major',
                    title: '专业方向'
                },
                {
                    field: 'phone',
                    title: '联系电话'
                },
                {
                    field: 'email',
                    title: '邮箱'
                },
                {
                    field: 'isActive',
                    title: '是否在职',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isActiveDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.teacherId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.teacherId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
        $(function() {
            $.table.init(options);
        });

        // 为表格工具类添加下载模板方法
        $.table.exportTemplate = function() {
            var url = options.exportTemplateUrl;
            if (url) {
               $.get(url, {}, function(result) {
                if (result.code == 0) {
                    // 构造下载链接
                    var url = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    // 创建隐藏的<a>标签并触发点击事件
                    $('<a></a>').attr('href', url).attr('download', result.msg)[0].click();
                } else {
                    $.modal.alertError(result.msg);
                }
            });
            } else {
                $.modal.alertWarning("未配置下载模板URL");
            }
        };
    </script>
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
</body>
</html>